package com.guofen.controller.sjq;

import com.guofen.pojo.SjqWaterProductionEquipmentInspection;
import com.guofen.service.sjq.SjqWaterProductionEquipmentInspectionService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/SjqWaterProductionEquipmentInspection")
@Controller
@Api(tags = "SjqWaterProductionEquipmentInspectionController", description = "已弃用！——水处理生产现场记录表（设备检查)")
public class SjqWaterProductionEquipmentInspectionController {
    @Autowired
    private SjqWaterProductionEquipmentInspectionService sjqWaterProductionEquipmentInspectionService;

    @ApiOperation("添加记录")
    @RequestMapping(value = "/addForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addForm(@ApiParam(name = "reflux_pump", value = "回流泵", required = true) @RequestParam String reflux_pump,
                          @ApiParam(name = "sludge_pump", value = "排泥泵", required = true) @RequestParam String sludge_pump,
                          @ApiParam(name = "pneumatic_valve_1", value = "气动阀1#", required = true) @RequestParam String pneumatic_valve_1,
                          @ApiParam(name = "pneumatic_valve_2", value = "气动阀2#", required = true) @RequestParam String pneumatic_valve_2,
                          @ApiParam(name = "membrane_module_1", value = "膜组件1#", required = true) @RequestParam String membrane_module_1,
                          @ApiParam(name = "membrane_module_2", value = "膜组件2#", required = true) @RequestParam String membrane_module_2,
                          @ApiParam(name = "membrane_level", value = "膜池液位计是否正常", required = true) @RequestParam String membrane_level,
                          @ApiParam(name = "remarks", value = "备注", required = false) @RequestParam String remarks){

        if (sjqWaterProductionEquipmentInspectionService.addForm(reflux_pump, sludge_pump, pneumatic_valve_1,
                pneumatic_valve_2,  membrane_module_1, membrane_module_2, membrane_level, remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("查询记录")
    @RequestMapping(value = "/findForm", method = RequestMethod.GET)
    @ResponseBody
    public Result findForm(){
        if (sjqWaterProductionEquipmentInspectionService.findForm() != null)
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentInspectionService.findForm());
        else
            return ResultGenerator.genFailResult("暂无记录");
    }


    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentInspectionService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name = "reflux_pump", value = "回流泵", required = true) @RequestParam String reflux_pump,
                         @ApiParam(name = "sludge_pump", value = "排泥泵", required = true) @RequestParam String sludge_pump,
                         @ApiParam(name = "pneumatic_valve_1", value = "气动阀1#", required = true) @RequestParam String pneumatic_valve_1,
                         @ApiParam(name = "pneumatic_valve_2", value = "气动阀2#", required = true) @RequestParam String pneumatic_valve_2,
                         @ApiParam(name = "membrane_module_1", value = "膜组件1#", required = true) @RequestParam String membrane_module_1,
                         @ApiParam(name = "membrane_module_2", value = "膜组件2#", required = true) @RequestParam String membrane_module_2,
                         @ApiParam(name = "membrane_level", value = "膜池液位计是否正常", required = true) @RequestParam String membrane_level,
                         @ApiParam(name = "remarks", value = "备注", required = false) @RequestParam String remarks) {
        SjqWaterProductionEquipmentInspection record = new SjqWaterProductionEquipmentInspection();
        record.setId(id);
        record.setRefluxPump(reflux_pump);
        record.setSludgePump(sludge_pump);
        record.setPneumaticValve1(pneumatic_valve_1);
        record.setPneumaticValve2(pneumatic_valve_2);
        record.setMembraneModule1(membrane_module_1);
        record.setMembraneModule2(membrane_module_2);
        record.setMembraneLevel(membrane_level);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentInspectionService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentInspectionService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentInspectionService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
